class StoryTelling extends MapBook {
    constructor() {
        this.alignments = {
            'left': 'lefty',
            'center': 'centered',
            'right': 'righty'
        };

        this.story = document.getElementById('book');
        this.features = document.createElement('div');
        this.header = document.createElement('div');
        this.footer = document.createElement('div');

        //初始化书籍
        this.book = new Book();
        this.book.mountMapBook(this);

        //初始化地图加载器
        this.mapLoader = new SimpleMapLoader();
        this.mapLoader.mountMapBook(this);

        //初始化插件
        this.plugins = new Array();
    }

    setMapLoader(mapLoader) {
        mapLoader.mountMapBook(that);
        this.mapLoader = mapLoader;
    }

    installPlugin(plugin) {
        plugin.mountMapBook(this);
        that.plugins.push(plugin);
    }

    //加载故事
    loadBook(mapContainer, config) {
        that.config = config;
        that.features.classList.add(that.alignments[config.alignment]);
        that.features.setAttribute('id', 'features');

        //地图加载器加载地图元素
        that.mapLoader.loadMap(mapContainer, config);
        that.book.loadBook(config);
        //执行地图加载成功后的回调
        that.map.on("load", function () {
            //页面版式加载故事
            that.book.onMapLoaded();
            that.plugins.forEach((plugin) => {
                if (plugin.onMapLoaded) {
                    plugin.onMapLoaded();
                }
            });
        });
    }
}